home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / fstwait.com / FASTWAIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-04-08  |  1.8 KB  |  77 lines

  1. {$A+,B-,E+,F-,I-,N-,O-,R-,S-,V-}
  2.  
  3. UNIT FastWait;
  4. (*     Version 1.00 - 4/8/91    *)
  5.  
  6. {$IfDef DEBUG}
  7.     {$D+,L+}
  8. {$Else}
  9.     {$D-,L-}
  10. {$EndIf}
  11.  
  12.  
  13. {════════════════════════════════════════════════════════════}
  14. INTERFACE
  15.  
  16.     VAR
  17. WaitOneMS        : word;        {number of loops to do for 1 ms wait}
  18. LoopsPerTick    : LongInt;    {number of loops per timer tick}
  19. BIOSTick        : LongInt absolute $40:$6C;    {system timer, 18.2/second}
  20.  
  21.  
  22. procedure Wait( ms    : word );
  23. {
  24.     Pauses execution of the program for "ms" milliseconds.
  25. }
  26.  
  27.  
  28. {$IfNDef VER40}    {$IfNDef VER50}    {$IfNDef VER55}
  29. procedure ShortDelay(NumLoops : word);
  30. {
  31.   This procedure is for very short timing loops ( < 1ms) that cannot be
  32.   handled by the delay routine.
  33.  
  34.   The variable "LoopsPerTick" has the number of loops to do for one BIOS
  35.   tick (18.2 of these/sec). If you want to delay for "X" µs, the number of loops
  36.   required would be  "(LoopsPerTick*X) div 54945"
  37.  
  38.   This will not compile if you are using TP 4.0, 5.0 or 5.5 due to the
  39.   conditional defines.  This is because it makes use of the "asm" statement
  40.   which is not available in TP versions prior to 6.0.
  41. }
  42. {$EndIf}    {$EndIf}    {$EndIf}
  43.  
  44.  
  45.  
  46. {════════════════════════════════════════════════════════════}
  47. IMPLEMENTATION
  48.  
  49. {$L WAIT.OBJ}
  50.  
  51. procedure Wait( ms : word );    external;
  52.  
  53. procedure WaitInit;            external;
  54.  
  55. {$IfNDef VER40}    {$IfNDef VER50}    {$IfNDef VER55}
  56. procedure ShortDelay(NumLoops : word); assembler;
  57. asm
  58.      mov  cx,NumLoops
  59.      jcxz @@2
  60.      xor  di,di         {ES:DI points to dummy address}
  61.      mov  es,di         { which won't change}
  62.      mov  al,es:[di]    {AL has the value there}
  63. @@1:
  64.      cmp  al,es:[di]
  65.      jne  @@2
  66.     loop @@1
  67. @@2:
  68. end;
  69. {$EndIf}    {$EndIf}    {$EndIf}
  70.  
  71.  
  72.  
  73.  
  74. begin        {Code to execute at start-up to calibrate the loop delay}
  75. WaitInit;
  76. end.
  77.